package main

import (
	"fmt"
	"strconv"
)

//演示golang中string转成基本数据类型
func main() {

	var str string = "hellook"
	var b bool = true
	//b,_ = strconv.ParseBool(str)
	//说明
	//1.strconv.ParseBool(str) 函数会返回这两个值(value bool,err error)
	//2.因为我只想获取到 value bool,不想获取 err 所以我使用_忽略
	b, _ = strconv.ParseBool(str)
	fmt.Printf("b type %T b=%v\n", b, b)

	var str2 string = "1234590"
	var n1 int64
	var n2 int
	//参数1:字符串	参数2:进制	参数3:int64
	n1, _ = strconv.ParseInt(str2, 10, 64)
	n2 = int(n1)
	fmt.Printf("n1 type %T n1=%v\n", n1, n1)
	fmt.Printf("n2 type %T n2=%v\n", n2, n2)

	var str3 string = "123.456"
	var f1 float64
	f1, _ = strconv.ParseFloat(str3, 64)
	fmt.Printf("f1 type is %T f1=%v\n", f1, f1)

	//注意:
	var str4 string = "hello"
	var n3 int64 = 11
	n3, _ = strconv.ParseInt(str4, 10, 64)
	fmt.Printf("n3 type: %T n3=%v", n3, n3)
}
